package com.softer.wxzj.controller;


import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.aop.annotation.LogRecord;
import com.softer.wxzj.common.aop.enums.LogOperationType;
import com.softer.wxzj.common.aop.enums.LogOperationUnit;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.entity.*;
import com.softer.wxzj.service.BaseOwnerCommitteeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * DiccontentController class
 *
 * @author wxr
 * @date 2019/4/10
 */
@RestController
@RequestMapping("/baseOwnerCommittee")
@Slf4j
public class BaseOwnerCommitteeController {
    @Autowired
    BaseOwnerCommitteeService baseOwnerCommitteeService;

    /**
     * 根据id查询变更详情
     *
     * @param baseModifyDetail 变更类型
     * @return
     */
    @RequestMapping("/getModifyDetailList")
    @LogRecord(description = "根据id查询变更详情", operationUnit = LogOperationUnit.BASE_ORGANIZATION, operationType = LogOperationType.SELECT)
    public PageInfo<BaseModifyDetail> getModifyDetailList(Page page, BaseModifyDetail baseModifyDetail) {
        return baseOwnerCommitteeService.getModifyDetailList(page, baseModifyDetail);
    }

    /**
     * 添加审核
     *
     * @param id      业务ID
     * @param opinion 审核意见
     * @param mark    审批通过 audit_pass
     *                审批否决 audit_veto
     *                审批退回 audit_back
     * @return 审核结果
     */
    @RequestMapping("/addAudit")
    public CommonResult audit(@RequestParam("id") String id, String opinion, @RequestParam("mark") String mark) {
        return baseOwnerCommitteeService.addAudit(id, opinion, mark);
    }


    /**
     * 获取待审核信息列表
     *
     * @param page
     * @param baseOwnerCommittee
     * @return
     */
    @RequestMapping("/getAuditList")
    @LogRecord(description = "获取业委会信息列表", operationUnit = LogOperationUnit.Base_Owner_Committee, operationType = LogOperationType.SELECT)
    public PageInfo<BaseOwnerCommittee> getAuditList(Page page, BaseOwnerCommittee baseOwnerCommittee, String flowType) {
        return baseOwnerCommitteeService.getAuditList(page, baseOwnerCommittee, flowType);
    }

    /**
     * 业委会添加
     *
     * @param baseOwnerCommittee
     * @return
     */
    @RequestMapping("/add")
    @LogRecord(description = "业委会添加", operationUnit = LogOperationUnit.Base_Owner_Committee, operationType = LogOperationType.INSERT)
    public CommonResult add(@RequestBody BaseOwnerCommittee baseOwnerCommittee) {
        return baseOwnerCommitteeService.insertToId(baseOwnerCommittee);
    }

    /**
     * 业委会保存时修改
     *
     * @param baseOwnerCommittee
     * @return
     */
    @RequestMapping("/update")
    @LogRecord(description = "业委会保存时修改", operationUnit = LogOperationUnit.Base_Owner_Committee, operationType = LogOperationType.UPDATE)
    public CommonResult update(@RequestBody BaseOwnerCommittee baseOwnerCommittee) {
        return baseOwnerCommitteeService.update(baseOwnerCommittee);
    }

    /**
     * 业委会删除
     *
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    @LogRecord(description = "业委会删除", operationUnit = LogOperationUnit.Base_Owner_Committee, operationType = LogOperationType.DELETE)
    public CommonResult delete(String id) {
        return baseOwnerCommitteeService.delete(id);
    }

    /**
     * 业委会查询
     *
     * @param page
     * @param baseOwnerCommittee
     * @return
     */
    @RequestMapping("/getList")
    @LogRecord(description = "审批流程类型列表查询", operationUnit = LogOperationUnit.DIC_CONTENT, operationType = LogOperationType.SELECT)
    public PageInfo<BaseOwnerCommittee> getList(Page page, BaseOwnerCommittee baseOwnerCommittee) {
        return baseOwnerCommitteeService.getList(page, baseOwnerCommittee);
    }

    /**
     * 业务会变更: 新增一条变更记录以及增加变更详情
     *
     * @param baseOwnerCommittee
     * @return
     */
    @RequestMapping("/updateToSave")
    @LogRecord(description = "业务会审核通过变更信息", operationUnit = LogOperationUnit.Base_Owner_Committee, operationType = LogOperationType.UPDATE)
    public CommonResult updateToSave(@RequestBody BaseOwnerCommittee baseOwnerCommittee) throws Exception {
        return baseOwnerCommitteeService.updateToSave(baseOwnerCommittee);
    }

    /**
     * 查询业委会详情
     *
     * @param id      业委会ID
     * @param arcType 图档大类
     * @return 业委会实体
     */
    @RequestMapping("/getInfo")
    @LogRecord(description = "查询单条数据", operationUnit = LogOperationUnit.Base_Owner_Committee, operationType = LogOperationType.SELECT)
    public BaseOwnerCommittee getInfo(String id, String arcType) {
        return baseOwnerCommitteeService.getInfoById(id, arcType);
    }


    /**
     * 业主居委会变更审核
     * BaseModifyReq 根据id 更改变更原因（追加）
     * 在终审结束时 更改当前的 flow_state 的状态 同意  拒绝
     * 更改业务表 base_owner_committee 的基本信息
     *
     * @param id      业务记录 id（前端传）
     * @param opinion 前端传值 原因
     * @param mark    前端传值 同意拒绝
     * @return
     */
    @RequestMapping("/changeResidentialCommittee")
    @LogRecord(description = "业主居委会变更审核", operationUnit = LogOperationUnit.Base_Owner_Committee, operationType = LogOperationType.UPDATE)
    public CommonResult changeResidentialCommittee(String id, String opinion, String mark) {
        return baseOwnerCommitteeService.changeResidentialCommittee(id, opinion, mark);
    }

    /**
     * 备案
     *
     * @param baseOwnerCommittee recDate备案时间now
     *                           state 备案1 撤销备案0
     * @return
     */
    @RequestMapping("/record")
    @LogRecord(description = "业主居委会备案", operationUnit = LogOperationUnit.Base_Owner_Committee, operationType = LogOperationType.UPDATE)
    CommonResult record(BaseOwnerCommittee baseOwnerCommittee) {
        return baseOwnerCommitteeService.record(baseOwnerCommittee);
    }

    /**
     * 备案
     *
     * @param baseOwnerCommittee recDate备案时间now
     *                           state 备案1 撤销备案0
     * @return
     */
    @RequestMapping("/updateAndAdd")
    @LogRecord(description = "业主居委会备案", operationUnit = LogOperationUnit.Base_Owner_Committee, operationType = LogOperationType.UPDATE)
    public CommonResult updateAndAdd(@RequestBody BaseOwnerCommittee baseOwnerCommittee) {
        return baseOwnerCommitteeService.updateAndAdd(baseOwnerCommittee);
    }

    /**
     * 变更审核
     *
     * @param id      业务Id
     * @param opinion 审核意见
     * @param mark    审批通过 audit_pass
     *                审批否决 audit_veto
     *                审批退回 audit_back
     * @return 审核结果
     */
    @RequestMapping("/updateAudit")
    public CommonResult updateAudit(@RequestParam("id") String id, String opinion, @RequestParam("mark") String mark) {
        return baseOwnerCommitteeService.updateAudit(id, opinion, mark);
    }

    /**
     * 保存并提交（注册备案提交按钮）
     */
    @RequestMapping("/insertSaveAndSubmit")
    @LogRecord(description = "业主居委会保存并提交", operationUnit = LogOperationUnit.Base_Owner_Committee, operationType = LogOperationType.INSERT)
    public CommonResult insertSaveAndSubmit(String id) {
        return baseOwnerCommitteeService.insertSaveAndSubmit(id, null);
    }

    /**
     * 查看登录人可以看基本信息么
     */
    @RequestMapping("/selectWhoLogin")
    @LogRecord(description = "业主居委会查看单个信息", operationUnit = LogOperationUnit.Base_Owner_Committee, operationType = LogOperationType.INSERT)
    public CommonResult selectWhoLogin(String id) {
        return baseOwnerCommitteeService.selectWhoLogin(id);
    }

    /**
     * 外网保存并提交
     *
     * @param baseOwnerCommittee
     * @return
     */
    @RequestMapping("/submitAuditAndAdd")
    @LogRecord(description = "外网保存并提交", operationUnit = LogOperationUnit.Base_Owner_Committee, operationType = LogOperationType.INSERT)
    public CommonResult submitAuditAndAdd(@RequestBody BaseOwnerCommittee baseOwnerCommittee) {
        return baseOwnerCommitteeService.submitAuditAndAdd(baseOwnerCommittee);
    }

    /**
     * 查询审核驳回
     */
    @RequestMapping("/rejectionExaminationApproval")
    public BaseOwnerCommittee rejectionExaminationApproval(String operNo, String arcType) {
        return baseOwnerCommitteeService.rejectionExaminationApproval(operNo, arcType);
    }

    /**
     * 获取外网业委会确认变更接口
     *
     * @param modifyVO 变更项集合
     * @return 变更结果
     */
    @RequestMapping("/getExtraNetModify")
    @LogRecord(description = "获取外网业委会确认变更接口", operationUnit = LogOperationUnit.Base_Owner_Committee, operationType = LogOperationType.SELECT)
    public CommonResult getExtraNetModify(@RequestBody ModifyVO modifyVO) {
        return baseOwnerCommitteeService.getExtraNetModify(modifyVO);
    }

    /**
     * 外网获取变更信息列表
     *
     * @param page               分页信息
     * @param baseOwnerCommittee 查询信息
     * @return 业委会变更列表
     */
    @RequestMapping("/getModifyListToExtraNet")
    @LogRecord(description = "外网获取变更信息列表", operationUnit = LogOperationUnit.Base_Owner_Committee, operationType = LogOperationType.SELECT)
    public PageInfo<BaseOwnerCommittee> getModifyListToExtraNet(Page page, BaseOwnerCommittee baseOwnerCommittee) {
        return baseOwnerCommitteeService.getModifyListToExtraNet(page, baseOwnerCommittee);
    }

    /**
     * 校验小区是否存在业委会或者居委会
     *
     * @param regionId 小区ID
     * @return true/false
     */
    @RequestMapping("/checkRegion")
    @LogRecord(description = "校验小区是否存在业委会或者居委会", operationUnit = LogOperationUnit.Base_Owner_Committee, operationType = LogOperationType.SELECT)
    public Boolean checkRegion(String regionId) {
        return baseOwnerCommitteeService.checkRegion(regionId);
    }

    /**
     * 查询业委会/居委会的小区列表
     *
     * @param page           分页信息
     * @param baseRegionInfo 查询实体
     * @return 小区列表
     */
    @PostMapping("/getOrgRegionList")
    @LogRecord(description = "查询业委会/居委会的小区列表", operationUnit = LogOperationUnit.Base_Owner_Committee, operationType = LogOperationType.SELECT)
    public PageInfo<BaseRegionInfo> getOrgRegionList(Page page, BaseRegionInfo baseRegionInfo) {
        return baseOwnerCommitteeService.getOrgRegionList(page, baseRegionInfo);
    }

    /**
     * 外网查询业委会/居委会管理的小区
     *
     * @param operNo 登录账号
     * @return 小区列表
     */
    @PostMapping("/getCommitteeRegionList")
    public List<BaseRegionInfo> getCommitteeRegionList(String operNo) {
        return baseOwnerCommitteeService.getCommitteeRegionList(operNo);
    }
}
